package com.xmut.web;

import com.sirdc.modules.core.web.JsonBaseController;
import com.sirdc.modules.core.web.model.Message;
import com.sirdc.modules.sys.databean.SysUserDataBean;
import com.sirdc.modules.sys.service.SysUserService;
import com.sirdc.modules.sys.util.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *
 */
@Controller
@RequestMapping("/register")
public class RegisterController extends JsonBaseController {

    @Autowired
    private SysUserService sysUserService;

    @Override
    protected String getView(String view) {
        return "/front/" + view;
    }

    /**
     * 返回注册页面
     * @return
     */
    @RequestMapping(method = RequestMethod.GET)
    public String showRegisterPage(@ModelAttribute SysUserDataBean databean, Model model) {
        model.addAttribute("databean",databean);
        return getView("register");
    }

    /**
     * 执行注册
     * @return
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST)
    public Message register(@ModelAttribute SysUserDataBean databean) {
        databean.setDeptId("20150130100000000040");
        databean.setRoleId("02");
        try{
            sysUserService.saveUserLogin(databean);
        } catch (Exception e){
            return coverMessage("500", e.getMessage());
        }
        return coverMessage("200");
    }
}
